#include<cstdio>
#include<iostream>

using namespace std;

void merge(int* left, int* right, int, int);

int main()
{
	int unsorted[] = {9,8,5,6,2,1,4,5,10,0,30};
	//int* sorted = merge_sort(unsorted);
	cout << " unsorted array: " << unsorted << endl;
	int l[] = { 0, 1, 5, 9, 10, 60, 100};
	int r[] = { 30, 50, 110};
	merge(l, r, 7, 3);
}

int* merge_sort(int uns[])
{
	int length = sizeof(uns) / sizeof(int);
	
	if(length <= 1)
	{
		return uns;
	}

	int left[5];
	int right[6];



	for ( int i =  0; i < length / 2 ; ++i )
	{
		left[i] = uns[i];
	}
	for ( int j = length / 2, i = 0; j < length; ++j, ++i )
	{
		right[i] = uns[j];
	}


}

void merge(int* left, int* right , int l_len, int r_len)
{
	int merged[l_len + r_len];
	int count = 0;
	int l_count = 0;
	int r_count = 0;
	while(count < (l_len + r_len))
	{
		if((r_count >= r_len) || (left[l_count] < right[r_count]))
		{
			merged[count++] = left[l_count++];
		} else if((l_count >= l_len) || (left[l_count] >= right[r_count]))
		{
			merged[count++] = right[r_count++];
		}
	}
	for(int y = 0; y < ( l_len + r_len ); ++y)
	{
		cout << merged[y] << endl;
	}
}
			

